//
//  MainViewController.swift
//  CBWWeiBo
//
//  Created by 陈博文 on 16/1/7.
//  Copyright © 2016年 陈博文. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    // MARK:=============== lazy ===============
    /// 发布按钮
    lazy var composeBtn : UIButton = {
        // 1.创建btn
        let composeBtn = UIButton(imageName: "tabbar_compose_icon_add", bgImageName: "tabbar_compose_button")
        // 2.设置位置
        composeBtn.center = CGPoint(x: self.tabBar.center.x, y: self.tabBar.bounds.size.height * 0.5)
        // 3.监听按钮的点击
        composeBtn.addTarget(self, action: "composeBtnClick", forControlEvents: .TouchUpInside)
//        CBWLog("----")
        return composeBtn
    }()
    
    // MARK:=============== viewDidLoad ===============
    override func viewDidLoad() {
        super.viewDidLoad()
        //创建中间的按钮
        tabBar.addSubview(composeBtn)

    }
    // MARK:=============== viewWillAppear ===============
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)

        adjustItems()
    }
    
    // MARK:=============== composeBtnClick ===============
    /// 监听中间按钮的点击
    @objc private func composeBtnClick() {
        CBWLog("1223")
    }
    
    // MARK:=============== adjustItems ===============
    private func adjustItems() {
        for i in 0..<tabBar.items!.count {
            // 1.1.取出item
            let item = tabBar.items![i]
            
            // 2.如果是第二个item,让其失效,循环继续
            if i == 2 {
                item.enabled = false
                continue
            }
        }
    }

}
